# 环境变量
PORT=2181
ZOOKEEPER_HOME=/opt/module/zookeeper/$PORT
ZOOKEEPER_DATA=$ZOOKEEPER_HOME/data
ZOOKEEPER_LOG=$ZOOKEEPER_HOME/datalog
ZOOKEEPER_CONF=$ZOOKEEPER_HOME/zoo.cfg

mkdir -p $ZOOKEEPER_DATA
mkdir -p  $ZOOKEEPER_LOG
touch  $ZOOKEEPER_CONF
chmod 666 $ZOOKEEPER_CONF
sudo cat >$ZOOKEEPER_CONF<<EOF
dataDir=/data
dataLogDir=/datalog
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=60
standaloneEnabled=true
admin.enableServer=true
server.1=localhost:2888:3888;2181
EOF


docker run -d \
    --name zookeeper-$PORT \
    -p $PORT:2181 \
    -v $ZOOKEEPER_DATA:/data \
    -v $ZOOKEEPER_LOG:/datalog \
    -v $ZOOKEEPER_CONF:/conf/zoo.cfg \
    zookeeper
echo "客户端：docker exec -it zookeeper-$PORT bin/zkCli.sh"

